sasecurityfandomcom-20200214-history
Ycombinator good buy object oriented programming
goodbye object oriented https://medium.com/@cscalfani/goodbye-object-oriented-programming-a59cda4c0e53 https://www.reddit.com/r/PHP/comments/6828cm/is_oop_a_lie_or_is_it_just_misused/ if you blindly create hierarchies then your code will be a mess. Inheritance represents a very tight coupling between two objects and so should only be used where necessary. Declaring encapsulation to fall to references misses the point of encapsulation. Public, protected, and private variables are a useful feature that many languages provide but encapsulation isn't about preventing access it's about centralizing data. Encapsulation let's you focus on the operations that you can perform so that the data format can change as needed. If you build a program that relies on that internal format or breaks the invariants of your operation then you've written a buggy program. The final point that OO is bad because polymorphism can be achieved through interfaces is silly. Object oriented programming is about dividing your program's data into self contained units - the nouns of your program - and about pairing those units with the specific operations that apply to that data - the verbs - so that you can focus more on performing actions and less on maintaining the data format. An interface defines a collection of related operations that that you can perform on any bit of data with a specific property. They are a key tool in deciding how to split your data in the first place and so are an essential aspect of OO. This article misunderstands OO. First, it is one tool for code organization out of many. C++ gets this right in most of the standard library by using small objects with few methods and relying on a large body of free functions to manipulate those objects generically. Objects only have the methods they require and are composed of a set of interfaces (often defined implicitly by templated functions) allowing object oriented and functional styles to be used together ycombinator https://news.ycombinator.com/item?id=12154228 And this guy has supposedly been writing in OO languages for decades? What? This is the bit i don't get. It's like he learned OOP in the '90s, when everyone thought inheritance was rad and nobody had realised how terrible mutating shared state was, and then fell asleep for twenty years. None of this article, none of it, has any relevance to how OOP is practiced by informed people today. flukus on July 25, 2016 - The keyword there is informed. There are still plenty of shops that practice OOP this way. I'm working at one right now and there are OOP horrors around every corner. Unfortunately, they seem intent on adding more mutable state rather then eliminating it. vikiomega9 on July 25, 2016 - Do you have anecdotes you can share? :D flukus on July 25, 2016 - Quite a few, but the worst would be the custom logger. I got lost trying to trace the inheritance graph. which spans projects, and the dependency graph, loggers within loggers within loggers. I gave up when I ran out of space trying to sketch the relationships in my notepad. Being encapsulated means you don't actually have any control over the logger, or the threads it spins up. Creating a logger for a new app requires inheriting from a application logger (which is already 3 or 4 layers deep in the inheritance hierarchy. The distinction other loggers make between the log interface and the appenders are non-existent. If you want to log to a new source (say the event log) you have to add a new layer to the inheritance tree. Then there's the fact that it's handling the application state, in an "on error resume next" kind of way. And this is a global state, so don't even think about multi threading. Naturally, actually accessing the logger is done via a singleton. It causes more problems than it helps resolve, and the ones it causes naturally don't have an diagnostic information available. There are plenty of others, but it's hard to top this tour de force of OO anti patterns. If only there was some free and stable alternative... 4 justin_vanw on July 27, 2016 - map, filter, etc are not 'functional'. 'functional' doesn't mean 'functions'. It is all about side effects, and that the procedures in the language are like mathematical functions: without state or side effects. Using your definition, virtually every language in use today is 'functional', all the way down to Fortran 77, since really any language you can get a pointer or other handle to a function or callable object would let you implement map, filter, etc. Really the existence of map, filter, etc are not a clue to a language being 'functional'. Yes, you would need such things, but they are not sufficient. C is not a 'functional language', even though technically you can write C that is completely functional in style. In fact, almost any modern language can be used in a 100% functional style, avoiding side effects and state completely. Nobody does this. Even if it is one of your favorite things, virtually no one uses functional languages. This isn't because people are dumb, it's because functional languages are cumbersome and inefficient. lispm on July 28, 2016 - I would not think passing procedure pointers in C makes it able to support functional programming. That's very shallow. C lacks (last I looked) nested functions, closures, functions as first class data types, ... > Really the existence of map, filter, etc are not a clue to a language being 'functional'. 'Functional Programming' isn't black and white. There are pure languages which ENFORCE functional programming like Haskell. It's their many paradigm, the language and its library make heavy use of FP and one has to actively manage side-effects. Then there are language which SUPPORT some forms of functional programming, for example by providing a subset in the language and its libraries which can be used side-effect free, makes use of higher-order functions, etc. At the bottom are languages which ENABLE some basic functional programming idioms. Though most of the language and its libraries are not using FP, the user can still use some FP constructs like nested functions, closures, etc. Generally I agree, that pure FP is not that much used in the real world because of a lot actual problems (difficult to learn/use/maintain, efficiency might be achievable by experts, needs understanding of slightly advanced mathematical concepts, ...). There are some more or less used implementation languages of more or less pure FP (GHC, OCAML, F#, ..., Clojure) languages. I'd guess that the main applications are in domains where they have highly skilled people: finance, data analytics, verification/specification, ... I sometimes see that companies advertise use of FP languages, but in reality that's marketing in recruiting to look cool and to attract clever people (who then have to work on Java jobs, mostly). qwertyuiop924 on July 29, 2016 - I wasn't making the point that map and filter were functional, I was trying to say that those were concepts originating in FP. And that they appear in so many languages demonstrates some of FP's influence. 5 5 closures http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html http://okmij.org/ftp/Scheme/oop-in-fp.txt Let's consider behavior, which is often understood as an ability to send an object a message to which it replies. To put in other terms, we invoke a dispatcher function of the object and pass it an indicator of a message along with other parameters. The result of that function is the reply. As far as the external world is concerned, this dispatcher function is the representation of the object -- it *is* the object. Well, an object has to encapsulate and maintain a state -- thus the dispatcher function should be a closure. The identity aspect depends: if the dispatcher function is a pure function, or if it can mutate its own state ("closed" variables) in response to some messages. ftp://ftp.cs.indiana.edu/pub/scheme-repository/doc/pubs/swob.txt An object "instance" consists of local (encapsulated) state and a reference to shared code which operates on its state. The easy way to think of this is as a C struct or Pascal record which has one field reserved for a pointer to its shared code environment and other slots for its instance variables. Each procedure in this shared environment is called a "method." A "class" is code which is can generate instances (new records) by initializing their fields, including a pointer to the instance's shared method environment. The environment just maps method names to their values (their code). Each method is a procedure which takes the record it is operating on as its first, sometimes hidden, argument. The first argument is called the "reciever" and typically aliased to the name "self" within the procedure's code. 5 MawNicker on July 25, 2016 - Object Oriented Programming simulates the restrained reasoning capacity of the real world. This is done by weaving state into every conceivable unit of computation. The result is a universal and inescapable notion of identity. It's a state conspiracy! Sometimes you are actually interacting with the real world and this is an appropriate constraint. That is only because, in the real real world, these things are pervasively intertwined. Right down to the smallest phenomena we've been able to observe. We can't actually take them apart except for in our minds. To do so is a very old idea, pervasively apparent in western thought, called platonic realism. I internalized it as an unknown known at some point. I imagine that's just how people did it before someone as smart as Plato was able to articulate it. It's sort of the doorway to abstract thought. Most mathematically inclined people have ventured into the depths of the world it conceals. It's necessary in order to properly understand the concept of a "value". When these people first start to program they rely heavily on expressions and functions. They tend to atomize complex values with simple structs. They don't know they're doing it but they're writing "functional" programs. It might be more apparent if we just called them mathematical or algebraic programs. They demonstrate a preference for referential transparency without knowing what it is. Much of their code is outright stateless. They're hesitant to use a "var" as anything but a "let". Many seem to immediately grasp the simplicity and generality of recursion. They have to have it pried away from them like it's a dangerous recreational drug. That recursion is not "optimal" is simply presented as an engineering reality. Always intent on incremental improvement they diligently internalize these "optimal" representations utilizing loops and state. They're tricked into feeling they've acquired a worthwhile skill; They don't know they're doing what a compiler ought to. They learn to reserve the truly optimal representations for their minds eye. With the desire to utilize their new "skill" they move towards external representations that could only be considered "optimal" by an unconscious machine. All of this damage is done in the earliest stages of learning; Probably before they've even attempted any significant programmatic interaction with the real world. That's when everything gets worse. They start trying to coordinate too much state and they can't cope. They're told they need these object things. Everything seems to get easier: Sockets, Widgets and even the Lists that had been such a struggle to use before. They choke down the declaration syntax and hastily strap their newfangled constructor and destructor gadgets onto their toolbelts. These are excellent tools for arbitrating the abstract world and the real one. The ability to hook into their creation and destruction provides abstract objects with a canonical state-of-existence. This is necessary to fully simulate the identity possessed by real objects. For the purposes that they've learned them, objects are immediately and overwhelmingly useful. They come to appreciate the clarity of the method invocation syntax for manipulating state. They're right to do so. The functional languages themselves even sort of "do" it. Tragically with their most fundamental notions of computation already brutally violated by the state conspiracy, they're vulnerable to seeing objects as a universal paradigm. Everything is an object. Everything. They ascribe pet-hood to their little objects and feel driven by the satisfaction of teaching them their own special tricks. Each and every one of them is an excessively black box. Some go so far as to make social-networks called UML diagrams to protect them from inappropriate "friends". They have forgotten the elegant abstract world that was left for them by the intellectual giants of history. They descended from it in pursuit of mere performance and are in serious danger of never returning. To act like it's just another way of looking at things is a brutal misunderstanding. It's a discipline that resides entirely within a much larger one that it is not a suitable replacement for. Despite the confusing desperation of non-academics for it to be that. Even it's creators are disappointed by it's dominance. MawNicker on July 25, 2016 - Well I can't edit it now. It was mostly a rant anyway. The widely held assumption that OOP is a universal paradigm has done unfathomable damage to Computer Science. It implies nothing more than that every Turing machine is a Turing machine. Then after ignoring every other factor it declares itself supreme based on nothing but it's adjacency to the one Turing machine we were already stuck with. I constantly see people fall for this contrivance in various forms. They just can't stand up to it when it's presented alongside the credence of industry. links oop , noun Oop comments Category:Oop Category:Oop comments